package edu.jiefengli.course_selection_system.controller;

import edu.jiefengli.course_selection_system.pojo.entity.Course;
import edu.jiefengli.course_selection_system.pojo.entity.Result;
import edu.jiefengli.course_selection_system.pojo.vo.CourseStudent;
import edu.jiefengli.course_selection_system.service.CourseRecordService;
import edu.jiefengli.course_selection_system.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/teacher")
public class TeacherController {
    @Autowired
    private CourseService courseService;
    @Autowired
    private CourseRecordService courseRecordService;

    @GetMapping("/course")
    public Result<List<Course>> getCourseListByTeacherId(int teacherId){
        return Result.success(courseService.getCourseByTeacherId(teacherId));
    }

    @GetMapping("/course/detail")
    public Result<CourseStudent> getCourseDetail(int courseId){
        CourseStudent cs = new CourseStudent();
        cs.setCourse(courseService.getCourseById(courseId));
        cs.setStudent(courseRecordService.getSelectedCourseStudent(courseId));
        return Result.success(cs);
    }
}
